package com.itheima.jedis;

import java.util.ResourceBundle;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisPoolUtils {

//			//获取jedis池的配置对象
//			JedisPoolConfig jc=new JedisPoolConfig();
//			//配置最大连接数
//			jc.setMaxTotal(20);
//			//配置等待超时时间
//			jc.setMaxWaitMillis(8000);
	
	private static JedisPoolConfig jc = null;
	private static int maxTotal = 0;
	private static long maxWaitMillis = 0;
	private static String host = null;
	private static int port=0;
	private static JedisPool pool=null;
	static{
		jc=new JedisPoolConfig();
		//获取properties中的配置数据
		ResourceBundle re = ResourceBundle.getBundle("jedis");
		maxTotal=Integer.parseInt(re.getString("maxTotal"));
		maxWaitMillis=Long.parseLong(re.getString("maxWaitMillis"));
		
		jc.setMaxTotal(maxTotal);
		jc.setMaxWaitMillis(maxWaitMillis);
		host = re.getString("host");
		port = Integer.parseInt(re.getString("port"));
		//创建Jedis池
	     pool=new JedisPool(jc, host, port);
		
	}
	
	public static Jedis getJedis(){
		return pool.getResource();
		
	}
}
